package com.example.hemin.fnb.ui.presenter;

import android.content.Context;

import com.example.hemin.fnb.ui.base.BasePresenter;
import com.example.hemin.fnb.ui.base.FindRankBean;
import com.example.hemin.fnb.ui.bean.BaseObjectBean;
import com.example.hemin.fnb.ui.bean.Find2Bean;
import com.example.hemin.fnb.ui.bean.Find4Bean;
import com.example.hemin.fnb.ui.bean.Find5Bean;
import com.example.hemin.fnb.ui.bean.FindBean;
import com.example.hemin.fnb.ui.bean.FindDeilyBean;
import com.example.hemin.fnb.ui.bean.FindFirstBean;
import com.example.hemin.fnb.ui.bean.FindHuaBean;
import com.example.hemin.fnb.ui.bean.FindHuoListBean;
import com.example.hemin.fnb.ui.bean.FindLoveBean;
import com.example.hemin.fnb.ui.bean.MessageBean1;
import com.example.hemin.fnb.ui.contract.FindContract;
import com.example.hemin.fnb.ui.model.FindModel;
import com.example.hemin.fnb.ui.net.RxScheduler;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import io.reactivex.functions.Consumer;

public class FindPresenter extends BasePresenter<FindContract.View> implements FindContract.Presenter {
    private FindContract.huo modle;
    private FindContract.addNum modle2;
    private FindContract.hua modle3;
    private FindContract.huas modle4;
    private FindContract.js modle5;
    private FindContract.cn modle6;
    private FindContract.dianzan modle7;
    private FindContract.dianzans modle8;
    private FindContract.modle1 za;
    private FindContract.DzScXy dcy;
    private List<FindBean> beansDate = new ArrayList<>();
    private List<String> imageUrls = new ArrayList<>();
    private List<String> pathUrl = new ArrayList<>();
    private String activityUrl, intentUrl, GiveNum, CollectionNum, WantNum;
    private Object dates = new ArrayList<>();
    private ArrayList<String> deilyUrlList = new ArrayList<>();

    public FindPresenter() {
        modle = new FindModel();
        modle2 = new FindModel();
        modle3 = new FindModel();
        modle4 = new FindModel();
        modle5 = new FindModel();
        modle6 = new FindModel();
        modle7 = new FindModel();
        modle8 = new FindModel();
        za = new FindModel();
        dcy = new FindModel();

    }

    @Override
    public void pageListHuo(Context context, Map<String, String> heard, long id, long size) {
        if (!isViewAttached()) {
            return;
        }

   String data1 = "{\"total\":\"2\"\n" +
           " ,\"size\":\"3\",\n" +
           "\"pages\":\"1\",\n" +
           "\"current\":\"1\"\n" +
           ",\"records\":[\n" +
           "{\"activityId\":1,\"activityName\":null,\"activityContentUrl\":\"http://h5.eqxiu.com/ls/7gRL4YtE\",\"activityUrl\":\"https://wan-jian.oss-cn-hangzhou.aliyuncs.com/images/wcqevg9psf\",\"activityType\":null,\"activityNum\":2,\"userId\":null,\"activitySort\":null,\"createTime\":null,\"updateTime\":null},{\"activityId\":2,\"activityName\":null,\"activityContentUrl\":\"http://h5.eqxiu.com/ls/5cEJGBE2\",\"activityUrl\":\"https://wan-jian.oss-cn-hangzhou.aliyuncs.com/images/d89yzu7enx\",\"activityType\":null,\"activityNum\":3,\"userId\":null,\"activitySort\":null,\"createTime\":null,\"updateTime\":null}\n" +
           "]\n" +
           "\n" +
           "\n" +
           "}";
        Gson gson = new Gson();
        FindHuoListBean.DataBean bean1 = gson.fromJson(data1,new TypeToken<FindHuoListBean.DataBean>(){}.getType());
        List<FindHuoListBean.DataBean.RecordsBean> list = bean1.getRecords();
                        for (int i = 0; i < list.size() && list.size() < 4; i++) {
                            activityUrl = list.get(i).getActivityUrl();
                            intentUrl = list.get(i).getActivityContentUrl();
                            FindBean beansDatec = new FindBean(activityUrl, intentUrl, 1, 4);
                            beansDate.add(beansDatec);
                        }


                        mView.Date(beansDate, 1);
        mView.onSuccess(1);


//        modle.pageListHuo(context, heard, id, size)
//                .compose(RxScheduler.<BaseObjectBean>Flo_io_main())
//                .as(mView.<BaseObjectBean>bindAutoDispose())
//                .subscribe(new Consumer<BaseObjectBean>() {
//                    @Override
//                    public void accept(BaseObjectBean bean) throws Exception {
//                        mView.onSuccess(bean);
//
//                        FindHuoListBean.DataBean bean1 = (FindHuoListBean.DataBean) bean.getResult();
//                        List<FindHuoListBean.DataBean.RecordsBean> list = bean1.getRecords();
//                        for (int i = 0; i < list.size() && list.size() < 4; i++) {
//                            activityUrl = list.get(i).getActivityUrl();
//                            intentUrl = list.get(i).getActivityContentUrl();
//                            FindBean beansDatec = new FindBean(activityUrl, intentUrl, 1, 4);
//                            beansDate.add(beansDatec);
//                        }
//
//
//                        mView.Date(beansDate, 1);
//                    }
//                }, new Consumer<Throwable>() {
//                    @Override
//                        public void accept(Throwable throwable) throws Exception {
//                            mView.onError(throwable);
//                            mView.hideLoading();
//
//
//                    }
//                });
    }

    @Override
    public void addNum(Context context, Map<String, String> heard, long activityId, long userId) {

    }


    @Override
    public void addHua(Context context, Map<String, String> heard, long current, long size) {
        if (!isViewAttached()) {
            return;
        }

        String data2 = "{\"total\":\"1\"\n" +
                " ,\"size\":\"1\",\n" +
                "\"pages\":\"1\",\n" +
                "\"current\":\"1\"\n" +
                ",\"records\": [{\"topicId\":1,\"topicName\":\"111\",\"userId\":14,\"topicContent\":\"https://www.baidu.com\",\"topicSimple\":\"\",\"topicNum\":1,\"topicSort\":0,\"topicType\":1,\"topicUrl\":\"https://wan-jian.oss-cn-hangzhou.aliyuncs.com/images/lftswe3mph\",\"createTime\":\"2019-05-27 17:17:19\",\"updateTime\":\"2019-05-27 17:17:23\"}]}\n";
        Gson gson = new Gson();
        Find2Bean.DataBean bean1 = gson.fromJson(data2,new TypeToken<Find2Bean.DataBean>(){}.getType());
                        List<Find2Bean.DataBean.RecordsBean> list = bean1.getRecords();
                        mView.Date(list, 2);
        mView.onSuccess(1);
//        modle3.addHua(context, heard, current, size)
//                .compose(RxScheduler.<BaseObjectBean>Flo_io_main())
//                .as(mView.<BaseObjectBean>bindAutoDispose())
//                .subscribe(new Consumer<BaseObjectBean>() {
//                    @Override
//                    public void accept(BaseObjectBean bean) throws Exception {
//                        mView.onSuccess(bean);
//
//                        Find2Bean.DataBean beans = (Find2Bean.DataBean) bean.getResult();
//                        List<Find2Bean.DataBean.RecordsBean> list = beans.getRecords();
//                        mView.Date(list, 2);
//                    }
//                }, new Consumer<Throwable>() {
//                    @Override
//                    public void accept(Throwable throwable) throws Exception {
//                        mView.onError(throwable);
//                        mView.hideLoading();
//                    }
//                });

    }

    @Override
    public void huas(Context context, Map<String, String> heard, long topicId, long userId) {

    }

    @Override
    public void getDaily(Context context, Map<String, String> heard, long userId) {
        if (!isViewAttached()) {
            return;
        }
        String data3 ="{\"data\" : {\"collectionId\":1,\"collectionNum\":\"430408875\",\"ctName\":\"石器\",\"collectionDetails\":\"啊 dasd 啊\",\"list\":[{\"imagesId\":1,\"imagesUrl\":\"https://wan-jian.oss-cn-hangzhou.aliyuncs.com/images/wpn89sy3gk\",\"ieId\":8,\"ieName\":\"审核通过\"},{\"imagesId\":2,\"imagesUrl\":\"https://wan-jian.oss-cn-hangzhou.aliyuncs.com/images/95xwvyng7m\",\"ieId\":8,\"ieName\":\"审核通过\"},{\"imagesId\":3,\"imagesUrl\":\"https://wan-jian.oss-cn-hangzhou.aliyuncs.com/images/4tkvmlgr2n\",\"ieId\":8,\"ieName\":\"审核通过\"},{\"imagesId\":4,\"imagesUrl\":\"https://wan-jian.oss-cn-hangzhou.aliyuncs.com/images/wg4xf5ukz9\",\"ieId\":8,\"ieName\":\"审核通过\"},{\"imagesId\":5,\"imagesUrl\":\"https://wan-jian.oss-cn-hangzhou.aliyuncs.com/images/au9ygbfpqs\",\"ieId\":8,\"ieName\":\"审核通过\"}],\"dailyId\":1,\"giveNum\":1,\"isGiveNum\":0,\"collectionSum\":1,\"isCollectionSum\":0,\"wantNum\":1,\"isWantNum\":0}}";
        Gson gson = new Gson();
        FindDeilyBean.DataBean  beans = gson.fromJson(data3,new TypeToken<FindDeilyBean.DataBean>(){}.getType());
                        mView.Date(beans, 3);
        mView.onSuccess(1);
//        modle5.getDaily(context, heard, userId)
//                .compose(RxScheduler.<BaseObjectBean>Flo_io_main())
//                .as(mView.<BaseObjectBean>bindAutoDispose())
//                .subscribe(new Consumer<BaseObjectBean>() {
//                    @Override
//                    public void accept(BaseObjectBean bean) throws Exception {
//                        deilyUrlList.clear();
//                        mView.onSuccess(bean);
//
//                        FindDeilyBean.DataBean bean1 = (FindDeilyBean.DataBean) bean.getResult();
//                        mView.Date(bean1, 3);
//                    }
//                }, new Consumer<Throwable>() {
//                    @Override
//                    public void accept(Throwable throwable) throws Exception {
//                        mView.onError(throwable);
//                        mView.hideLoading();
//                    }
//                });
    }

    @Override
    public void guessLove(Context context, Map<String, String> heard) {
        if (!isViewAttached()) {
            return;
        }

    String data4 = "{\"data\":[{\"collectionId\":20,\"imagesUrl\":\"https://wan-jian.oss-cn-hangzhou.aliyuncs.com/images/tgylkvsc43\",\"certificateNum\":\"\",\"insuranceNum\":\"\",\"collectionAht\":\"真品无误\",\"caId\":1,\"collectionCost\":\"无价之宝\",\"collectionTime\":\"新石器时代\",\"collectionAppearance\":\"残品（补）\",\"collectionType\":\"玉器\"},{\"collectionId\":1,\"imagesUrl\":\"https://wan-jian.oss-cn-hangzhou.aliyuncs.com/images/wpn89sy3gk\",\"certificateNum\":\"\",\"insuranceNum\":\"\",\"collectionAht\":\"真品无误\",\"caId\":1,\"collectionCost\":\"无价之宝\",\"collectionTime\":\"旧石器时代\",\"collectionAppearance\":\"全品\",\"collectionType\":\"石器\"}]}";
        Gson gson = new Gson();
//        Find4Bean  beans = gson.fromJson(data4,new TypeToken<Find4Bean>(){}.getType());
        Find4Bean list =  gson.fromJson(data4,new  TypeToken<Find4Bean>(){}.getType());
        List<Find4Bean.DataBean> lists = (List<Find4Bean.DataBean>) list.getData();
        mView.Date(lists.get(0), 4);
        mView.onSuccess(1);
//        modle6.guessLove(context, heard)
//                .compose(RxScheduler.<BaseObjectBean>Flo_io_main())
//                .as(mView.<BaseObjectBean>bindAutoDispose())
//                .subscribe(new Consumer<BaseObjectBean>() {
//                    @Override
//                    public void accept(BaseObjectBean bean) throws Exception {
//                        mView.onSuccess(bean);
//
//                        List<Find4Bean.DataBean> list = (List<Find4Bean.DataBean>) bean.getResult();
//                        mView.Date(list.get(0), 4);
//
//
//                    }
//                }, new Consumer<Throwable>() {
//                    @Override
//                    public void accept(Throwable throwable) throws Exception {
//                        mView.onError(throwable);
//                        mView.hideLoading();
//                    }
//                });
    }

    @Override
    public void getRankingList(Context context, Map<String, String> heard, long current, long size) {
        if (!isViewAttached()) {
            return;
        }

      String data5 = "{\"data\":{\"total\":1,\"size\":10,\"pages\":1,\"current\":1,\"records\":[{\"collectionId\":1,\"giveNum\":2,\"collectionNum\":2,\"wantNum\":2,\"imagesUrl\":\"https://wan-jian.oss-cn-hangzhou.aliyuncs.com/images/wpn89sy3gk\"}]}}";
        Gson gson = new Gson();
        Find5Bean  beans = gson.fromJson(data5,new TypeToken<Find5Bean>(){}.getType());
        Find5Bean.DataBean bean1 = (Find5Bean.DataBean) beans.getData();
        List<Find5Bean.DataBean.RecordsBean> list = bean1.getRecords();
        mView.Date(list.get(0), 5);
        mView.onSuccess(1);
//        modle7.getRankingList(context, heard, current, size)
//                .compose(RxScheduler.<BaseObjectBean>Flo_io_main())
//                .as(mView.<BaseObjectBean>bindAutoDispose())
//                .subscribe(new Consumer<BaseObjectBean>() {
//                    @Override
//                    public void accept(BaseObjectBean bean) throws Exception {
//                        mView.onSuccess(bean);
//
//                        Find5Bean.DataBean bean1 = (Find5Bean.DataBean) bean.getResult();
//                        List<Find5Bean.DataBean.RecordsBean> list = bean1.getRecords();
//                        mView.Date(list.get(1), 5);
//                    }
//                }, new Consumer<Throwable>() {
//                    @Override
//                    public void accept(Throwable throwable) throws Exception {
//                        mView.onError(throwable);
//                        mView.hideLoading();
//                    }
//                });
    }

    @Override
    public void getRanking(Context context, Map<String, String> heard, long collectionId) {

    }

    @Override
    public void getMaga(Context context, Map token, long current, long size, String type, final int status) {
        if (!isViewAttached()) {
            return;
        }

   String data6 = "{\"data\":{\"total\":1,\"size\":10,\"pages\":1,\"current\":1,\"records\":[{\"magazineId\":1,\"magazineName\":\"玩瓷人群的三个层次\",\"magazineStage\":\"第一期\",\"magazineUrl\":\"https://wan-jian.oss-cn-hangzhou.aliyuncs.com/images/65sfwkdgbx\",\"updateTime\":\"2019-05-27 09:46:06\",\"nickname\":\"test\"},{\"magazineId\":1,\"magazineName\":\"玩瓷人群的三个层次\",\"magazineStage\":\"第一期\",\"magazineUrl\":\"https://wan-jian.oss-cn-hangzhou.aliyuncs.com/images/65sfwkdgbx\",\"updateTime\":\"2019-05-27 09:46:06\",\"nickname\":\"test\"},{\"magazineId\":1,\"magazineName\":\"玩瓷人群的三个层次\",\"magazineStage\":\"第一期\",\"magazineUrl\":\"https://wan-jian.oss-cn-hangzhou.aliyuncs.com/images/65sfwkdgbx\",\"updateTime\":\"2019-05-27 09:46:06\",\"nickname\":\"test\"}]}}";
        Gson gson = new Gson();
        MessageBean1  beans = gson.fromJson(data6,new TypeToken<MessageBean1>(){}.getType());
        MessageBean1.DataBean bean1 = (MessageBean1.DataBean) beans.getData();
        List<MessageBean1.DataBean.RecordsBean> list = bean1.getRecords();
        mView.Date(list, 6);
        mView.onSuccess(1);
//        za.getMaga(context, token, current, size, type)
//                .compose(RxScheduler.<BaseObjectBean>Flo_io_main())
//                .as(mView.<BaseObjectBean>bindAutoDispose())
//                .subscribe(new Consumer<BaseObjectBean>() {
//                    @Override
//                    public void accept(BaseObjectBean bean) throws Exception {
//                        mView.onSuccess(bean);
//
//                        MessageBean1.DataBean bean1 = (MessageBean1.DataBean) bean.getData();
//                        List<MessageBean1.DataBean.RecordsBean> list = bean1.getRecords();
//                        mView.Date(list, 6);
//
//
//                    }
//                }, new Consumer<Throwable>() {
//                    @Override
//                    public void accept(Throwable throwable) throws Exception {
//                        mView.onError(throwable);
//                        mView.hideLoading();
//                    }
//                });
    }

    @Override
    public void getDCX(Context context, Map token, long type, long dailyId, long userId, int status) {
        if (!isViewAttached()) {
            return;
        }
        mView.Date("111",7);

//        dcy.getDCX(context, token, type, dailyId, userId)
//                .compose(RxScheduler.<BaseObjectBean>Flo_io_main())
//                .as(mView.<BaseObjectBean>bindAutoDispose())
//                .subscribe(new Consumer<BaseObjectBean>() {
//                    @Override
//                    public void accept(BaseObjectBean bean) throws Exception {
//                        mView.onSuccess(bean);
//
//                      mView.Date("111",7);
//
//
//                    }
//                }, new Consumer<Throwable>() {
//                    @Override
//                    public void accept(Throwable throwable) throws Exception {
//                        mView.onError(throwable);
//                        mView.hideLoading();
//                    }
//                });
    }
}
